/*
 * Created by SharpDevelop.
 * Author: Joey
 * Date: 26/09/2007
 * Time: 22:04
 * 
 * Source is copyright Joey Sabey 2007
 */

using System;
using System.Drawing;
using System.Windows.Forms;

namespace MonoTheism
{
	/// <summary>
	/// Description of OptionsDialogue.
	/// </summary>
	public partial class OptionsDialogue : Form
	{
		private bool bAcceptChanges = false;
		public bool AcceptChanges
		{
			get{return bAcceptChanges;}
		}
		
		public OptionsDialogue()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			foreach(string s in Options.AutoBuild)
			{
				TreeNode tn = new TreeNode(s);
				tn.Tag = s;
				treeAutoBuild.Nodes.Add(tn);
			}
		}
		
		void TsbAddAutoBuildClick(object sender, EventArgs e)
		{
			AutoBuild_Properties abpDialogue = new AutoBuild_Properties();
			abpDialogue.ShowDialog();
			if(abpDialogue.AcceptChanges)
			{
				TreeNode tnBuffer = new TreeNode(abpDialogue.Path);
				tnBuffer.Tag = abpDialogue.Path;
				treeAutoBuild.Nodes.Add(tnBuffer);
			}
		}
		
		void TsbRemoveAutoBuildClick(object sender, EventArgs e)
		{
			try
			{
				if(treeAutoBuild.SelectedNode == null)
					throw new Warning("Nothing was selected");
				treeAutoBuild.SelectedNode.Remove();
			}
			catch(Warning warn)
			{
				warn.Show();
			}
		}
		
		void TsbEditAutoBuildClick(object sender, EventArgs e)
		{
			try
			{
				if(treeAutoBuild.SelectedNode == null)
					throw new Warning("Nothing was selected");
				AutoBuild_Properties abpDialogue = new AutoBuild_Properties((string)treeAutoBuild.SelectedNode.Tag);
				abpDialogue.ShowDialog();
				if(abpDialogue.AcceptChanges)
				{
					treeAutoBuild.SelectedNode.Text = abpDialogue.Path;
					treeAutoBuild.SelectedNode.Tag = abpDialogue.Path;
				}
			}
			catch(Warning warn)
			{
				warn.Show();
			}
		}
		
		void BtOkClick(object sender, EventArgs e)
		{
			//update auto builds
			String_List sl = new String_List();
			foreach(TreeNode tn in treeAutoBuild.Nodes)
			{
				sl.Add((string)tn.Tag);
			}
			Options.AutoBuild = sl;
			
			Options.Save();
			
			this.bAcceptChanges = true;
			Close();
		}
		
		void BtCancelClick(object sender, EventArgs e)
		{
			Close();
		}
	}
}
